<?php
    cria_variaveis($_POST,$_GET,$_FILES);
?> 
<p class=titulo align=center><?php echo $msg->get('EQNL_MSG_02') ?></p>
<p class=subtitulo align=center><?php echo $msg->get('EQNL_MSG_03c') ?></p>
<p>
<div class="tabbar">
    <ul>
    <li><a href="index.php?inc=eqnl3.php&modo=material"<?php if ($_SESSION['ANAWEB']->RetornaModoExecucao() == "material") echo " class=\"tabact\""; ?>><?php echo $msg->get('Material_Teorico') ?></a></li>
    <li><a href="index.php?inc=eqnl3.php&modo=exemplo"<?php if ($_SESSION['ANAWEB']->RetornaModoExecucao() == "exemplo") echo " class=\"tabact\""; ?>><?php echo $msg->get('Exemplos_Prontos') ?></a></li>
    <li><a href="index.php?inc=eqnl3.php&modo=teclado"<?php if ($_SESSION['ANAWEB']->RetornaModoExecucao() == "teclado") echo " class=\"tabact\""; ?>><?php echo $msg->get('Entrada_Teclado') ?></a></li>
    </ul>
</div>
<div id="cas">
<?php
    if (!isset($Calcular)) {
        if ($_SESSION['ANAWEB']->RetornaModoExecucao() == "material")
        {
            require_once("./classes/upload.php");
            $uploads = new Upload();
            $uploads->Lista("reseqnl");
        }
        else if ($_SESSION['ANAWEB']->RetornaModoExecucao() == "exemplo" && !isset($opcao_execucao)) {
            //leitura de dados via banco de dados - modulo de exemplos e exercicios
            include "exibe_prob_eqnl3_xml.php";
        }
        // Final da Etapa I
        // Inicio da Etapa II - recolhe os dados via teclado ou exibe os dados extracaos do(s) arquivo(s) ou do banco de dados
        // A proxima etapa e executada no segundo arquivo do metodo, e a execucao propriamente dita do problema
        else if ($_SESSION['ANAWEB']->RetornaModoExecucao() == "teclado" || isset($opcao_execucao)) {
            if (strlen($opcao_execucao) == 0) {
                echo "<form method=post enctype=multipart/form-data action=index.php?inc=eqnl3.php>";
                echo "<p>".$msg->get('EQNL_MSG_41')."<br><br>";
                echo "<input type=radio name=opcao_execucao value=0> ".$msg->get('EQNL_MSG_42')."<br>";
                echo "<input type=radio name=opcao_execucao value=1> ".$msg->get('EQNL_MSG_43')."<br><br>";
                echo "<input type=hidden name=executar value=sim>";
                echo "<input class=button type=submit name=Submit value=".$msg->get('G_MSG_02').">";
                echo "</form>";
                echo "<form method=post enctype=multipart/form-data action=index.php?inc=eqnl3.php>";
                echo "<input class=button type=submit name=Submit value=".$msg->get('G_MSG_03').">";
                echo "</form>";
            }
            else if (($opcao_execucao == 0)and($deg == NULL) ) {
                //entrar com o valor do grau do polinomio no caso polinomial
                echo "<form method=post enctype=multipart/form-data action=index.php?inc=eqnl3.php>";
                echo "<p>".$msg->get('EQNL_MSG_04')."<br>";
                echo "<input type=text size='2' maxlength='2' name=deg value=".$deg."><br><br>";
                echo "<input type=hidden name=opcao_execucao value=0>";
                echo "<input type=hidden name=executar value=sim>";
                echo "<input class=button type=submit name=Submit value=".$msg->get('G_MSG_02').">";
                echo "</form>";
                echo "<form method=post enctype=multipart/form-data action=index.php?inc=eqnl3.php>";
                echo "<input class=button type=submit name=Submit value=".$msg->get('G_MSG_03').">";
                echo "</form>";
            }
            else if (((($opcao_execucao == 0)and($coef[1] == NULL))or(($opcao_execucao == 1)and($funcao == NULL)))and($error == NULL)and($it == NULL)) {
                //entrar com os coeficientes do polinomio/funcao de entrada e erro relativo e numero de iteracoes
                echo "<form method=post enctype=multipart/form-data action=index.php?inc=eqnl3.php>";
                if ($opcao_execucao == 0) {
                    //para caso polinomial
                    echo "<p>".$msg->get('EQNL_MSG_05')."<br>";
                    echo "f(x)=";
                    for($i = 0; $i < $deg; $i++) {
                        echo "<input type=text size=5 maxlength=5 name=coef[".$i."] value=".$coef[$i]."> x <sup>".($deg-$i)."</sup>+";
                    } // end for
                    echo "<input type=text size=5 maxlength=5 name=coef[".$deg."] value=".$coef[$deg]."><br><br>";
                    echo "<input type=hidden name=opcao_execucao value=0>";
                } //end if
                else if ($opcao_execucao == 1) {
                    //para caso geral
                    echo "<a href=javascript:winopen('ajuda/funcoesphp.php')>".$msg->get('G_MSG_29')."</a>";
                    echo "<p>";
                    echo $msg->get('EQNL_MSG_40')."<br><br>";
                    echo "f(x)= <input type=text size=60 maxlength=100 name=funcao value=".$funcao."><br>";
                    echo "<br>";
                    echo "<input type=hidden name=opcao_execucao value=1>";
                } // end if
                echo "".$msg->get('EQNL_MSG_06')."<br>";
                echo "<input type=text size=9 maxlength=9 name=error value=".$error."><br><br>";
                echo "".$msg->get('EQNL_MSG_07')."<br>";
                echo "<input type=text size=3 maxlength=3 name=it value=".$it."><br><br>";
                echo "<input type=hidden name=deg value=".$deg.">";
                echo "<input type=hidden name=d value=1>";
                echo "<input type=hidden name=executar value=sim>";
                echo "<input class=button type=submit name=Submit value=".$msg->get('G_MSG_02').">";
                echo "</form>";
                echo "<form method=post enctype=multipart/form-data action=index.php?inc=eqnl3.php>";
                echo "<input class=button type=submit name=Submit value=".$msg->get('G_MSG_03').">";
                echo "</form>";
            } else {
                if (!isset($_POST['Plotar']) && !isset($_POST['Calcular']))
                {
                echo "<form method=post name=formeqnl enctype=multipart/form-data action=index.php?inc=eqnl3.php>";
                echo "<p>";
                if ($_SESSION['ANAWEB']->RetornaModoExecucao() == "exemplo")
                    verificaBib($xml_file);
                echo "<br>";
                echo $msg->get('EQNL_MSG_08')."<br>";
                echo "f(x)=";
                if ($opcao_execucao == 0) {
                    //imprimir funcao polinomial
                    for($i = 0; $i < $deg; $i++) {
                        echo($coef[$i]);
                        echo("x<sup>");
                        echo($deg-$i);
                        echo("</sup>");
                        if ($coef[$i+1] >= 0) {
                            echo "+";
                        }
                    }
                    echo($coef[$deg]);
                    echo "<br>";
                    echo $msg->get('EQNL_MSG_09')." " .($deg). " <br>";
                } // end if opcao_execucao
                else if ($opcao_execucao == 1) {
                    //imprimir funcao qualquer
                    echo $funcao;
                    echo "<br>";
                } // end if opcao_execucao
                echo $msg->get('EQNL_MSG_10')." " .($error). " <br>";
                echo $msg->get('EQNL_MSG_11')." " .($it). "<br><br>";
                //cria a tabela de enumeracao de raizes do polinomio - **Caso polinomial**
                if ($opcao_execucao == 0) {
                    $tabela = enumera_raizes($coef, $deg);
                    echo "<table border=1 width=600 cellspacing=0>";
                    echo "   <th colspan=4>";
                    echo "      <p align=center>".$msg->get('EQNL_MSG_12')."</p>";
                    echo "   </th>";
                    //echo "</table>";
                    //echo "<table border=1 width=600 cellspacing=0>";
                    echo "   <tr>";
                    echo "       <td> <p align=center> <b>".$msg->get('EQNL_MSG_13')."</b> </p> </td>";
                    echo "       <td> <p align=center> <b>".$msg->get('EQNL_MSG_14')."</b> </p> </td>";
                    echo "       <td> <p align=center> <b>".$msg->get('EQNL_MSG_15')."</b> </p> </td>";
                    echo "       <td> <p align=center> <b>".$msg->get('EQNL_MSG_16')."</b> </p> </td>";
                    echo "   </tr>";
                    for ($i = 1; $i <= $tabela[0]["positiva"]; $i++) {
                        echo "<tr>";
                        echo "<td>";
                        echo "<p align=center>" .($tabela[$i]["positiva"]). "</p>";
                        echo "</td>";
                        echo "<td>";
                        echo "<p align=center>" .($tabela[$i]["negativa"]). "</p>";
                        echo "</td>";
                        echo "<td>";
                        echo "<p align=center>" .($tabela[$i]["complexa"]). "</p>";
                        echo "</td>";
                        echo "<td>";
                        $total = $tabela[$i]["positiva"] + $tabela[$i]["negativa"] + $tabela[$i]["complexa"];
                        echo "<p align=center>" .($total). "</p>";
                        echo "</td>";
                        echo "</tr>";
                    } // end for
                    echo "</table><br>";
                    // define as cotas superior e inferior **Caso polinomial** (Cota de Laguerre-Thibault)
                    /*if ($transf_positivo > 0)
                    $cota_superior = cotas($coef,$deg,"+");
                    else $cota_superior = 0;
                    if ($transf_negativo > 0)
                    $cota_inferior = -cotas($coef,$deg,"-");
                    else $cota_inferior = 0;*/

                    //cota (localizacao das raizes)
                    $absmax = abs($coef[$deg]);
                    for ($i = $deg; $i > 0; $i--) {
                        if (abs($coef[$i]) > $absmax)
                            $absmax = abs($coef[$i]);
                    }
                    $cotacalc = 1 + ((1 / abs($coef[0]) ) * $absmax);
                    $cota_superior = $cotacalc;
                    $cota_inferior = -1 * $cotacalc;
                    echo "<table border=1 width=600 cellspacing=0>";
                    echo "   <th colspan=2>";
                    echo "      <p align=center>".$msg->get('EQNL_MSG_17')."</p>";
                    echo "   </th>";
                    //echo "</table>";
                    //echo "<table border=1 width=600 cellspacing=0>";
                    echo "   <tr>";
                    echo "    <td>";
                    echo "      <p align=center> <b>".$msg->get('EQNL_MSG_18')."</b> </p>";
                    echo "    </td>";
                    echo "    <td>";
                    echo "      <p align=center> <b>".$msg->get('EQNL_MSG_19')."</b> </p>";
                    echo "    </td>";
                    echo "   </tr>";
                    echo "   <tr>";
                    echo "    <td>";
                    echo "      <p align=center>" .($cota_inferior). "</p>";
                    echo "    </td>";
                    echo "    <td>";
                    echo "      <p align=center>" .($cota_superior). "</p>";
                    echo "    </td>";
                    echo "   </tr>";
                    echo "</table>";
                } // end if opcao == 0 (polinomial)
                echo "<br>".$msg->get('Intervalo_Para_Plotar')."<br>";
                //echo "x<sub>0</sub>: <input type=text size=5 maxlength=5 name=x0 value=".($x0)."><br>";
                echo "[<input type=text size=5 maxlength=5 name=graphx1 value=".@$graphx1."> ; <input type=text size=5 maxlength=5 name=graphx2 value=".@$graphx2."> ]<br><br>";
                echo "<input type=hidden name=x0 value=".@$x0.">";
                echo "<input type=hidden name=executar value=sim>";
                echo "<input type=hidden name=it value=".$it.">";
                echo "<input type=hidden name=error value=".$error.">";
                echo "<input type=hidden name=mudagrafico value=sim>";
                if ($opcao_execucao == 0) {
                    echo "<input type=hidden name=deg value=".$deg.">";
                    echo "<input type=hidden name=d value=".@$d.">";
                    for($i = 0; $i < $deg; $i++) {
                        echo "<input type=hidden name=coef[] value=".@$coef[$i].">";
                    }
                    echo "<input type=hidden name=coef[] value=".@$coef[$deg].">";
                    echo "<input type=hidden name=opcao_execucao value=0>";
                } // end if opcao_execucao == 0
                if ($opcao_execucao == 1) {
                    echo "<input type=hidden name=funcao value=".$funcao.">";
                    echo "<input type=hidden name=opcao_execucao value=1>";
                } // end if opcao_execucao == 1
                echo "<p><p>";
                echo "<p>";
                if (isset($_POST["navegacao"]) && $_POST["navegacao"] == "sim") {
                    echo "<input type=\"hidden\" name=\"xml_file\" value=\"".$xml_file."\">";
                    echo "<input type=\"hidden\" name=\"indice\" value=\"$indice\">";
                    echo "<input type=\"hidden\" name=\"navegacao\" value=\"sim\">";
                }
                echo "<input type=hidden name=metodo value=newton>";
                //echo "<input class=button type=button name=Submit value=".(EQNL_MSG_25)." onClick=\"enviar()\"><br><br>";
                if (isset($_POST["respeqnl1"])) {
                    echo "<input type=\"hidden\" name=\"respeqnl1\" value=\"".$_POST["respeqnl1"]."\">";
                    echo "<input type=\"hidden\" name=\"itereqnl1\" value=\"".$_POST["itereqnl1"]."\">";
                }
                if (isset($_POST["respeqnl2"])) {
                    echo "<input type=\"hidden\" name=\"respeqnl2\" value=\"".$_POST["respeqnl2"]."\">";
                    echo "<input type=\"hidden\" name=\"itereqnl2\" value=\"".$_POST["itereqnl2"]."\">";
                }
                echo "<input class=button type=submit name=Plotar value=".$msg->get('EQNL_MSG_25').">";
                echo "<br>";
                echo "</form>";
                echo "<form method=post enctype=multipart/form-data action=index.php?inc=eqnl3.php>";
                echo "<input class=button type=submit name=Submit value=".$msg->get('G_MSG_03').">";
                echo "</form>";
                if (isset($_POST["navegacao"]) && $_POST["navegacao"] == "sim") {
                    echo "<form name=\"exemplos\" enctype=\"multipart/form-data\" method=\"post\">";
                    echo "<script language=\"javascript\" type=\"text/javascript\">\n";
                    echo "function criarLinks(value) {\n";
                    echo "document.exemplos.indice.value = value;\n";
                    echo "document.exemplos.action = 'index.php?inc=eqnl3.php&modo=exemplo'\n";
                    echo "document.exemplos.submit();\n";
                    echo "}\n";
                    echo "</script>";
                    echo "<input type=\"hidden\" name=\"id_bib\" value=\"".$id_bib."\">";
                    echo "<input type=\"hidden\" name=\"xml_file\" value=\"".$xml_file."\">";
                    echo "<input type=\"hidden\" name=\"indice\">";
                    echo "</form>";
                    echo $msg->get('Outros_Exemplos').":<br>";
                    $objeto = new DOMDocument();
                    $objeto->load($xml_file);
                	$filho = $objeto->getelementsbytagname("rootfinding");
                	if ($filho->length > 0)
                	{
                		$tmp=0;
                		$equation = $filho->item(0)->getelementsbytagname("equation");
                		for ($i = 0; $i < $equation->length; $i++)
                		{
                			$temp=$equation->item($i)->getelementsbytagname("option");
                			$temp1=$temp->item(0)->getattribute("data");
                			if ($temp1 == 'polynom')
                			{
                    			$tmp++;
                    			if ($i) echo " | ";
                    			if ($i == $indice) echo "<b>";
                    			echo "<a href=\"javascript:criarLinks($i);\"><u>".($tmp)."</u></a>";
                    			if ($i == $indice) echo "</b>";
                			}
                		}
                		for ($i = 0; $i < $equation->length; $i++)
                		{
                			$temp=$equation->item($i)->getelementsbytagname("option");
                			$temp1=$temp->item(0)->getattribute("data");
                			if ($temp1 == 'function')
                			{
                    			$tmp++;
                    			if ($i) echo " | ";
                    			if ($i == $indice) echo "<b>";
                    			echo "<a href=\"javascript:criarLinks($i);\"><u>".($tmp)."</u></a>";
                    			if ($i == $indice) echo "</b>";
                            }
                		}
                	}
                }
            } //end if
            else {
                echo "<form method=post name=formeqnl enctype=multipart/form-data action=index.php?inc=eqnl3.php>";
                echo "<p>";
                if ($_SESSION['ANAWEB']->RetornaModoExecucao() == "exemplo")
                    verificaBib($xml_file);
                echo "<br>";
                echo $msg->get('EQNL_MSG_08')."<br>";
                echo "f(x)=";
                if ($opcao_execucao == 0) { //imprimir funcao polinomial
                    for($i = 0; $i < $deg; $i++) {
                        echo $coef[$i]."x<sup>".($deg-$i)."</sup>";
                        if ($coef[$i+1] >= 0)
                            echo "+";
                    }
                    echo($coef[$deg])."<br>".$msg->get('EQNL_MSG_09')." ".($deg)." <br>";
                } // end if opcao_execucao
                else if ($opcao_execucao == 1) { //imprimir funcao qualquer
                    echo $funcao."<br>";
                } // end if opcao_execucao
                echo $msg->get('EQNL_MSG_10')." " .($error). " <br>";
                echo $msg->get('EQNL_MSG_11')." " .($it). "<br><br>";
                $dados_grafico = "$opcao_execucao|";
                if ($opcao_execucao == 0) {
                    $dados_grafico .= "$deg|";
                        for ($i=0;$i<=$deg;$i++) { $dados_grafico .= "$coef[$i]|" ;}
                } // end if
                if ($opcao_execucao == 1) {
                    $aux = normaliza_funcao($funcao);
                    $dados_grafico .= "$aux|";
                } // end if
                $dados_grafico .= "$graphx1|";
                $dados_grafico .= "$graphx2|";
                $arquivo = gera_nome_arquivo();
                $conn = &ADONewConnection($A_DB_TYPE);
                $conn->PConnect($A_DB_HOST,$A_DB_USER,$A_DB_PASS,$A_DB_DB);
                $sql = "INSERT INTO grafico(id,dados) values ('".$arquivo."','".$dados_grafico."');";
                $rs = $conn->Execute($sql);
                if ($rs === false) die(A_LANG_LOGIN_MSG5);
                $rs->Close();
                echo "<br>";
                echo "<table>";
                echo "<tr>";
                echo "<td><img src=eqnl_grafico.php?arquivo=".$arquivo."  border=0 align=center width=600 height= 400></td>";
                echo "</table>";
                echo "<br><br>";

                echo "<br>";
                echo $msg->get('EQNL_MSG_20c')."<br>";
                //echo "<p><font size=4>";
                //echo "[<input type=text size=5 maxlength=5 name=int1 value=".@$int1."> ; <input type=text size=5 maxlength=5 name=int2 value=".@$int2."> ]<br><br>";
                echo "x<sub>0</sub>: <input type=text size=5 maxlength=5 name=x0 value=".($x0)."><br>";
                echo "</font>";
                echo "<input type=hidden name=executar value=sim>";
                echo "<input type=hidden name=it value=".$it.">";
                echo "<input type=hidden name=error value=".$error.">";
                if ($opcao_execucao == 0) {
                    echo "<input type=hidden name=deg value=".$deg.">";
                    echo "<input type=hidden name=d value=".@$d.">";
                    for($i = 0; $i < $deg; $i++) {
                        echo "<input type=hidden name=coef[] value=".$coef[$i].">";
                    }
                    echo "<input type=hidden name=coef[] value=".$coef[$deg].">";
                    echo "<input type=hidden name=opcao_execucao value=0>";
                } // end if opcao_execucao == 0
                if ($opcao_execucao == 1) {
                    echo "<input type=hidden name=funcao value=".$funcao.">";
                    echo "<input type=hidden name=opcao_execucao value=1>";
                } // end if opcao_execucao == 1
                echo "<p><p>";
                if (@$correcao == "sim") {
                    echo "<input type=hidden name=correcao value=sim>";
                    echo "<input type=hidden name=resp value=".$resp.">";
                    echo "<input type=hidden name=resp_it value=".$resp_it.">";
                    echo "<b>".$msg->get('EQNL_MSG_21')."</b>";
                    echo "<br>";
                    echo $msg->get('EQNL_MSG_22')."".$resp."".$msg->get('EQNL_MSG_23')."".$resp_it."".$msg->get('EQNL_MSG_24');
                    echo "<p>";
                } // end if
                echo "<p>";
                if (isset($_POST["navegacao"]) && $_POST["navegacao"] == "sim") {
                    echo "<input type=\"hidden\" name=\"xml_file\" value=\"".$xml_file."\">";
                    echo "<input type=\"hidden\" name=\"indice\" value=\"$indice\">";
                    echo "<input type=\"hidden\" name=\"navegacao\" value=\"sim\">";
                }
                echo "<input type=\"hidden\" name=\"metodo\" value=\"bisseccao\">";
                //echo "<input class=button type=\"button\" name=\"Submit\" value=".(EQNL_MSG_25)."onClick=\"enviar()\"><br><br>";
                if (isset($_POST["respeqnl1"])) {
                    echo "<input type=\"hidden\" name=\"respeqnl1\" value=\"".$_POST["respeqnl1"]."\">";
                    echo "<input type=\"hidden\" name=\"itereqnl1\" value=\"".$_POST["itereqnl1"]."\">";
                }
                if (isset($_POST["respeqnl3"])) {
                    echo "<input type=\"hidden\" name=\"respeqnl3\" value=\"".$_POST["respeqnl3"]."\">";
                    echo "<input type=\"hidden\" name=\"itereqnl3\" value=\"".$_POST["itereqnl3"]."\">";
                }
                echo "<input type=hidden name=graphx1 value=".@$graphx1.">";
                echo "<input type=hidden name=graphx2 value=".@$graphx2.">";
                echo "<input class=button type=submit name=Calcular value=".$msg->get('G_MSG_04').">";
                if (isset($_POST['mudagrafico']))
                {
                    echo "<br><br><br>".$msg->get('Plotar_Outro_Intervalo').":<br>";
                    echo "[<input type=text size=5 maxlength=5 name=graphx1 value=".@$graphx1."> ; <input type=text size=5 maxlength=5 name=graphx2 value=".@$graphx2."> ]<br><br>";
                    echo "<input type=hidden name=mudagrafico value=sim>";
                    echo "<input class=button type=submit name=Plotar value=".$msg->get('EQNL_MSG_25').">";
                }
                echo "<br>";
                echo "</form>";
                echo "<form method=post enctype=multipart/form-data action=index.php?inc=eqnl2.php>";
                echo "<input class=button type=submit name=Submit value=".$msg->get('G_MSG_03').">";
                echo "</form>";
                if (isset($_POST["navegacao"]) && $_POST["navegacao"] == "sim") {
                    echo "<form name=\"exemplos\" enctype=\"multipart/form-data\" method=\"post\">";
                    echo "<script language=\"javascript\" type=\"text/javascript\">\n";
                    echo "function criarLinks(value) {\n";
                    echo "document.exemplos.indice.value = value;\n";
                    echo "document.exemplos.action = 'index.php?inc=eqnl2.php&modo=exemplo'\n";
                    echo "document.exemplos.submit();\n";
                    echo "}\n";
                    echo "</script>";
                    echo "<input type=\"hidden\" name=\"id_bib\" value=\"".$id_bib."\">";
                    echo "<input type=\"hidden\" name=\"xml_file\" value=\"".$xml_file."\">";
                    echo "<input type=\"hidden\" name=\"indice\">";
                    echo "</form>";
                    echo $msg->get('Outros_Exemplos').":<br>";
                    $objeto = new DOMDocument();
                    $objeto->load($xml_file);
                    $filho = $objeto->getelementsbytagname("rootfinding");
                    if ($filho->length > 0)
                    {
                        $tmp=0;
                        $equation = $filho->item(0)->getelementsbytagname("equation");
                        for ($i = 0; $i < $equation->length; $i++)
                        {
                            $temp=$equation->item($i)->getelementsbytagname("option");
                            $temp1=$temp->item(0)->getattribute("data");
                            if ($temp1 == 'polynom')
                            {
                                $tmp++;
                                if ($i) echo " | ";
                                if ($i == $indice) echo "<b>";
                                echo "<a href=\"javascript:criarLinks($i);\"><u>".($tmp)."</u></a>";
                                if ($i == $indice) echo "</b>";
                            }
                        }
                        for ($i = 0; $i < $equation->length; $i++)
                        {
                            $temp=$equation->item($i)->getelementsbytagname("option");
                            $temp1=$temp->item(0)->getattribute("data");
                            if ($temp1 == 'function')
                            {
                                $tmp++;
                                if ($i) echo " | ";
                                if ($i == $indice) echo "<b>";
                                echo "<a href=\"javascript:criarLinks($i);\"><u>".($tmp)."</u></a>";
                                if ($i == $indice) echo "</b>";
                            }
                        }
                    }
                }

            }
            echo "</body>";
        }
      }
        // end else
    } else {
        if ($_SESSION['ANAWEB']->RetornaModoExecucao() == "exemplo")
            verificaBib($xml_file);
        echo $msg->get('EQNL_MSG_08')."<br>";
        echo "f(x)=";
        if ($opcao_execucao == 0) {
            //imprimir funcao polinomial
            for($i = 0; $i < $deg; $i++) {
                echo($coef[$i]);
                echo("x<sup>");
                echo($deg-$i);
                echo("</sup>");
                if ($coef[$i+1] >= 0) {
                    echo "+";
                }
            }
            echo($coef[$deg]);
            echo "<br>";
            echo $msg->get('EQNL_MSG_09')."".($deg)."<br>";
        } // end if opcao_execucao
        else if ($opcao_execucao == 1) {
            //imprimir funcao qualquer
            echo $funcao;
            echo "<br>";
        } // end if opcao_execucao
        echo $msg->get('EQNL_MSG_10')."" .($error)."<br>";
        echo $msg->get('EQNL_MSG_11')."".($it)."<br>";
        echo $msg->get('EQNL_MSG_26c')."".($x0)."<br>";
        echo "<table border=1 width=30% cellspacing=0>";
        echo "   <tr>";
        echo "    <td>";
        echo "      <p align=center> <b>".$msg->get('EQNL_MSG_27')."</b> </p>";
        echo "    </td>";
        echo "    <td>";
        echo "      <p align=center> <b> x </b> </p>";
        echo "    </td>";
        echo "    <td>";
        echo "      <p align=center> <b> f(x) </b> </p>";
        echo "    </td>";
        echo "   </tr>";
        $j = 1;
        $stop = false;
        if ($opcao_execucao == 0) {
            $resx0 = Resolve($coef, $deg, $x0);
        } // end if
        else if ($opcao_execucao == 1) {
            $faux = normaliza_funcao($funcao).";";
            $x = $x0;
            eval ('$resx0='.$faux);
            //echo $i."<br>";
        } // end else
        echo "<tr><td align=\"center\">-</td><td align=\"center\">$x0</td><td align=\"center\">$resx0</td></tr>";
        if ($resx0 == 0) {
            echo "</table>";
            echo "<br><b>".$msg->get('EQNL_MSG_28')."</b><br>";
            echo $msg->get('EQNL_MSG_22')."".$x0."".$msg->get('EQNL_MSG_23')."0".$msg->get('EQNL_MSG_24');
        } else {
            while (($j < $it) && ($stop != true)) {
                if ($opcao_execucao == 0) {
                    // derivada para o caso polinomial
                    for($i = 0; $i < $deg; $i++) {
                        $coefdiff[$i] = $coef[$i] * ($deg-$i);
                    } // end for i1
                    $derivada = 0;
                    for($i = 0; $i < $deg-1; $i++) {
                        $derivada = $derivada+$coefdiff[$i] * potencia($x0, $deg- $i-1);
                    } // end for i2
                    $derivada = $derivada+$coefdiff[$deg-1];
                }
                else if ($opcao_execucao == 1 ) {
                    // derivada para qualquer funcao (derivacao numeica)
                    $derivada = deriva(normaliza_funcao($funcao).";", $it, "10", $x0, $error, "nao");
                } // end else if opcao_execucao
                if ($derivada == "erro") {
                    echo "</table><br>Um dos denominadores anulou-se durante o processo. Tente outras estimativas.<br><br>";
                    break;
                } // end if derivada
                if ((abs($derivada) >= $error) ) {
                    if ($opcao_execucao == 0) {
                        $resx0 = Resolve($coef, $deg, $x0);
                    } // end if
                    else if ($opcao_execucao == 1) {
                        $faux = normaliza_funcao($funcao).";";
                        $x = $x0;
                        eval ('$resx0='.$faux);
                    } // end else
                    $x1 = $x0-($resx0/$derivada);
                    $aux = max(1, abs($x1));
                    $err = abs($resx0/$derivada)/$aux;
                    if ($opcao_execucao == 0) {
                        $resx1 = Resolve($coef, $deg, $x1);
                    }
                    else if ($opcao_execucao == 1) {
                        $faux = normaliza_funcao($funcao).";";
                        $x = $x1;
                        eval ('$resx1='.$faux);
                    }
                    // imprimir as iteracoes na tela
                    echo "   <tr>";
                    echo "    <td>";
                    echo "      <p align=center>" .($j-1). "</p>";
                    echo "    </td>";
                    echo "    <td>";
                    echo "      <p align=center>" .($x1). "</p>";
                    echo "    </td>";
                    echo "    <td>";
                    echo "      <p align=center>" .($resx1). "</p>";
                    echo "    </td>";
                    echo "   </tr>";
                    if ($err < $error) {
                        echo "</table>";
                        echo "<br><b>".$msg->get('EQNL_MSG_28')."</b><br>";
                        echo $msg->get('EQNL_MSG_22')."".$x1."".$msg->get('EQNL_MSG_23')."".($j)."".$msg->get('EQNL_MSG_24');
                        $stop = true;
                        if ($opcao_execucao == 0) verifica_polino($coef, $deg, $x1);
                            elseif ($opcao_execucao == 1) verifica_funcao($funcao, $x1);
                        $encontrouresp = true;
                        $respencontrada = $x1;
                        $respiteracoes = $j;
                        if (isset($_POST["respeqnl1"]) && isset($_POST["respeqnl2"]))
                        {
                            echo $_POST["itereqnl1"]."/".$_POST["itereqnl2"]."/".$j;
                            if ($opcao_execucao==0) quadrocomp($_POST["respeqnl1"],$_POST["itereqnl1"],$_POST["respeqnl2"],$_POST["itereqnl2"],$x1,$j,0,$coef,$deg);
                            else  quadrocomp($_POST["respeqnl1"],$_POST["itereqnl1"],$_POST["respeqnl2"],$_POST["itereqnl2"],$x1,$j,1,$funcao);
                        }
                    } // end if err
                    if ($resx1 == 0) {
                        echo "</table>";
                        echo "<br><b>".$msg->get('EQNL_MSG_28')."</b><br>";
                        echo $msg->get('EQNL_MSG_29')."".$x1;
                        $stop = true;
                    } // end if resx1
                    if ($stop != true) {
                        $x0 = $x1;
                        $j++;
                    } // end if stop
                } //end if abs
                else
                    {
                    if (abs($derivada) < $error) {
                        echo "</table>";
                        echo "<br><b>".$msg->get('EQNL_MSG_28')."</b><br>";
                        echo $msg->get('EQNL_MSG_31');
                    } // end if abs
                    if ($derivada == "erro") {
                        echo $msg->get('EQNL_MSG_44');
                    } // end if derivada
                    $stop = true;
                } // end else
            } // end while
        } // end else
        if ($j >= $it) {
            echo "</table>";
            echo "<br><b>".$msg->get('EQNL_MSG_28')."</b><br>";
            echo $msg->get('EQNL_MSG_32')."".($j)."".$msg->get('EQNL_MSG_33');
        }
        echo "<br>";
        echo "<form method=post enctype=multipart/form-data action=index.php?inc=eqnl3.php>";
        if (isset($_POST["navegacao"]) && $_POST["navegacao"] == "sim") {
            echo "<input type=\"hidden\" name=\"xml_file\" value=\"".$xml_file."\">";
            echo "<input type=\"hidden\" name=\"indice\" value=\"$indice\">";
            echo "<input type=\"hidden\" name=\"navegacao\" value=\"sim\">";
        }
        if (isset($_POST["respeqnl1"])) {
            echo "<input type=\"hidden\" name=\"respeqnl1\" value=\"".$_POST["respeqnl1"]."\">";
            echo "<input type=\"hidden\" name=\"itereqnl1\" value=\"".$_POST["itereqnl1"]."\">";
        }
        if (isset($_POST["respeqnl2"])) {
            echo "<input type=\"hidden\" name=\"respeqnl2\" value=\"".$_POST["respeqnl2"]."\">";
            echo "<input type=\"hidden\" name=\"itereqnl2\" value=\"".$_POST["itereqnl2"]."\">";
        }
        echo "<input type=hidden name=executar value=sim>";
        echo "<input type=hidden name=resp value=".@$resp.">";
        echo "<input type=hidden name=correcao value=".@$correcao.">";
        echo "<input type=hidden name=resp_it value=".@$resp_it.">";
        echo "<input type=hidden name=it value=".@$it.">";
        echo "<input type=hidden name=error value=".@$error.">";
        if ($opcao_execucao == 0) {
            echo "<input type=hidden name=deg value=".$deg.">";
            echo "<input type=hidden name=d value=".$d.">";
            for($i = 0; $i < $deg; $i++) {
                echo "<input type=hidden name=coef[".$i."] value=".$coef[$i].">";
            }
            echo "<input type=hidden name=coef[] value=".$coef[$deg].">";
            echo "<input type=hidden name=opcao_execucao value=0>";
        } // end if opcao_execucao
        if ($opcao_execucao == 1) {
            echo "<input type=hidden name=funcao value=".$funcao.">";
            echo "<input type=hidden name=opcao_execucao value=1>";
        } // end if opcao_execucao
        echo "<input type=hidden name=graphx1 value=".@$graphx1.">";
        echo "<input type=hidden name=graphx2 value=".@$graphx2.">";
        echo "<input class=button type=submit name=Plotar value=".$msg->get('EQNL_MSG_35').">";
        //echo "<input class=button type=submit name=Submit value=".EQNL_MSG_35.">";
        echo "</form>";
        echo "<p>";
        echo $msg->get('G_PROXIMO_EXEMPLO')."<p>";
        // formulario para Metodo da Bisseccao
        echo "<form method=post enctype=multipart/form-data action=index.php?inc=eqnl1.php>";
        if (isset($_POST["navegacao"]) && $_POST["navegacao"] == "sim") {
            echo "<input type=\"hidden\" name=\"xml_file\" value=\"".$xml_file."\">";
            echo "<input type=\"hidden\" name=\"indice\" value=\"$indice\">";
            echo "<input type=\"hidden\" name=\"navegacao\" value=\"sim\">";
        }
        if (isset($encontrouresp) && $encontrouresp == true) {
            echo "<input type=\"hidden\" name=\"respeqnl3\" value=\"$respencontrada\">";
            echo "<input type=\"hidden\" name=\"itereqnl3\" value=\"$respiteracoes\">";
        }
        if (isset($_POST["respeqnl1"])) {
            echo "<input type=\"hidden\" name=\"respeqnl1\" value=\"".$_POST["respeqnl1"]."\">";
            echo "<input type=\"hidden\" name=\"itereqnl1\" value=\"".$_POST["itereqnl1"]."\">";
        }
        if (isset($_POST["respeqnl2"])) {
            echo "<input type=\"hidden\" name=\"respeqnl2\" value=\"".$_POST["respeqnl2"]."\">";
            echo "<input type=\"hidden\" name=\"itereqnl2\" value=\"".$_POST["itereqnl2"]."\">";
        }
        echo "<input type=hidden name=executar value=sim>";
        echo "<input type=hidden name=resp value=".@$resp.">";
        echo "<input type=hidden name=correcao value=".@$correcao.">";
        echo "<input type=hidden name=resp_it value=".@$resp_it.">";
        echo "<input type=hidden name=it value=".@$it.">";
        echo "<input type=hidden name=error value=".@$error.">";
        if ($opcao_execucao == 0) {
            echo "<input type=hidden name=deg value=".$deg.">";
            echo "<input type=hidden name=d value=".$d.">";
            for($i = 0; $i < $deg; $i++) {
                echo "<input type=hidden name=coef[".$i."] value=".$coef[$i].">";
            }
            echo "<input type=hidden name=coef[] value=".$coef[$deg].">";
            echo "<input type=hidden name=opcao_execucao value=0>";
        } // end if
        if ($opcao_execucao == 1) {
            echo "<input type=hidden name=funcao value=".$funcao.">";
            echo "<input type=hidden name=opcao_execucao value=1>";
        } // end if
        echo "<input class=button type=submit name=Submit value='".$msg->get('EQNL_MSG_03a')."'>";
        echo "</form>";
        // formulario para Metodo de Newton
        echo "<form method=post enctype=multipart/form-data action=index.php?inc=eqnl2.php>";
        if (isset($_POST["navegacao"]) && $_POST["navegacao"] == "sim") {
            echo "<input type=\"hidden\" name=\"xml_file\" value=\"".$xml_file."\">";
            echo "<input type=\"hidden\" name=\"indice\" value=\"$indice\">";
            echo "<input type=\"hidden\" name=\"navegacao\" value=\"sim\">";
        }
        if (isset($_POST["respeqnl1"])) {
            echo "<input type=\"hidden\" name=\"respeqnl1\" value=\"".$_POST["respeqnl1"]."\">";
            echo "<input type=\"hidden\" name=\"itereqnl1\" value=\"".$_POST["itereqnl1"]."\">";
        }
        if (isset($_POST["respeqnl2"])) {
            echo "<input type=\"hidden\" name=\"respeqnl2\" value=\"".$_POST["respeqnl2"]."\">";
            echo "<input type=\"hidden\" name=\"itereqnl2\" value=\"".$_POST["itereqnl2"]."\">";
        }
        echo "<input type=hidden name=executar value=sim>";
        echo "<input type=hidden name=resp value=".@$resp.">";
        echo "<input type=hidden name=correcao value=".@$correcao.">";
        echo "<input type=hidden name=resp_it value=".@$resp_it.">";
        echo "<input type=hidden name=it value=".@$it.">";
        echo "<input type=hidden name=error value=".@$error.">";
        if ($opcao_execucao == 0) {
            echo "<input type=hidden name=deg value=".$deg.">";
            echo "<input type=hidden name=d value=".$d.">";
            for($i = 0; $i < $deg; $i++) {
                echo "<input type=hidden name=coef[".$i."] value=".$coef[$i].">";
            }
            echo "<input type=hidden name=coef[] value=".$coef[$deg].">";
            echo "<input type=hidden name=opcao_execucao value=0>";
        } // end if
        if ($opcao_execucao == 1) {
            echo "<input type=hidden name=funcao value=".$funcao.">";
            echo "<input type=hidden name=opcao_execucao value=1>";
        } // end if
        echo "<input class=button type=submit name=Submit value='".$msg->get('EQNL_MSG_03b')."'>";
        echo "</form>";
        echo "<form method=post enctype=multipart/form-data action=index.php?inc=eqnl3.php>";
        echo "<input class=button type=submit name=Submit value=".$msg->get('G_MSG_03').">";
        echo "</form>";
        if (isset($_POST["navegacao"]) && $_POST["navegacao"] == "sim") {
            echo "<form name=\"exemplos\" enctype=\"multipart/form-data\" method=\"post\">";
            echo "<script language=\"javascript\" type=\"text/javascript\">\n";
            echo "function criarLinks(value) {\n";
            echo "document.exemplos.indice.value = value;\n";
            echo "document.exemplos.action = 'index.php?inc=eqnl3.php&modo=exemplo'\n";
            echo "document.exemplos.submit();\n";
            echo "}\n";
            echo "</script>";
            echo "<input type=\"hidden\" name=\"id_bib\" value=\"".@$id_bib."\">";
            echo "<input type=\"hidden\" name=\"xml_file\" value=\"".@$xml_file."\">";
            echo "<input type=\"hidden\" name=\"indice\">";
            echo "</form>";
            echo $msg->get('Outros_Exemplos').":<br>";
            $objeto = new DOMDocument();
            $objeto->load($xml_file);
        	$filho = $objeto->getelementsbytagname("rootfinding");
        	if ($filho->length > 0)
        	{
        		$tmp=0;
        		$equation = $filho->item(0)->getelementsbytagname("equation");
        		for ($i = 0; $i < $equation->length; $i++)
        		{
        			$temp=$equation->item($i)->getelementsbytagname("option");
        			$temp1=$temp->item(0)->getattribute("data");
        			if ($temp1 == 'polynom')
        			{
            			$tmp++;
            			if ($i) echo " | ";
            			if ($i == $indice) echo "<b>";
            			echo "<a href=\"javascript:criarLinks($i);\"><u>".($tmp)."</u></a>";
            			if ($i == $indice) echo "</b>";
        			}
        		}
        		for ($i = 0; $i < $equation->length; $i++)
        		{
        			$temp=$equation->item($i)->getelementsbytagname("option");
        			$temp1=$temp->item(0)->getattribute("data");
        			if ($temp1 == 'function')
        			{
            			$tmp++;
            			if ($i) echo " | ";
            			if ($i == $indice) echo "<b>";
            			echo "<a href=\"javascript:criarLinks($i);\"><u>".($tmp)."</u></a>";
            			if ($i == $indice) echo "</b>";
            		}
        		}
        	}
        }
    }
?>
</div>